<template>
<view class="">
	<view class="category">
		<view class="nav">
			<scroll-view class="bg" scroll-y="true" :scroll-top="scrollTop" :scroll-with-animation="true">
				<view class="nav-item" :class="{'ac':active == index}" v-for="(item,index) in 28" :key="index"
					@click="changeNav(index)">
					菜品{{index}}
				</view>
			</scroll-view>
		</view>
		<view class="goodsBox">
			<scroll-view scroll-y="true">
				<view class="goods">
					<view class="goods-item" v-for="(item,index) in 28" :key="index">
						<view class="food_wrap">
								<view class="food_item">
									<image class="food_image" src="../../static/logo.png"></image>
									<view class="food_name">11111</view>
									<view class="food_sum">￥1111</view>
									<button type="default" plain size="mini">加入购物车</button>
								</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
	<view style="width:100%;height: 80px;"></view>
	<view class="pay_wrap">
		<view class="">
			<image style="width: 24px;height: 24px;" src="/static/image/cat.png" mode=""></image>
			<view style="font-size: 12px;" class="">购物车</view>
		</view>
		<view class="pay_btn_wrap">
			<view class="" style="font-size: 20px;">￥18</view>
			<button type="default" style="background: #000000;color: #ffffff;margin-left: 15px;font-size: 15px;">去支付</button>
		</view>
	</view>
</view>
</template>
<script>
	export default {
		data() {
			return {
				active: 0,
				scrollTop: 0,
				height: 0
			}
		},
		onShow() {
			// 获取导航'.nav-item'的高度，在点击导航触发changeNav时，使其向下滚动
			this.$nextTick(() => {
				let height = uni.createSelectorQuery().select(".nav-item");
				height.boundingClientRect((data) => {
					this.height = data.height;
				}).exec()
			})
		},
		methods: {
			onClick(e) {
				uni.showToast({
				    title: `点击${e.content.text}`,
					icon: 'none'
				})
			},
			changeNav(index) {
				this.active = index;
				this.scrollTop = this.height * (index - 2);
				// 在这里请求接口 展示右侧商品数据
			}
		}
	}
</script>
<style scoped lang="scss">
	.category {
		display: flex;
		position: absolute;
		width: 100%;
		height: calc(100% - var(--status-bar-height));

		/* 隐藏滚动条样式 */
		::-webkit-scrollbar {
			width: 0;
			height: 0;
		}

		uni-scroll-view {
			height: 100%;
		}

		.bg {
			background: #F7F8F9;
		}

		.nav {
			width: 200rpx;

			.nav-item {
				width: 200rpx;
				height: 104rpx;
				line-height: 104rpx;
				background: #F7F8F9;
				font-size: 28rpx;
				color: #505660;
				text-align: center;
				position: relative;
			}

			.ac {
				color: #242724;
				font-size: 30rpx;
				background: #fff;
			}

			.ac:before {
				content: '';
				display: block;
				position: absolute;
				left: 0;
				top: 0;
				width: 6rpx;
				height: 104rpx;
				background: linear-gradient(180deg, #242724 0%, #242724 100%);
				border-radius: 2rpx;
			}
		}

		.goodsBox {
			background: #ffffff;
			.goods {
				display: flex;
				flex-wrap: wrap;
				padding: 30rpx 0;
				justify-content: space-around;

				.goods-item {
					text-align: center;
				}
			}
		}
	}
	.food_wrap {
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		align-items: center;
		justify-content: space-between;
		padding: 0px 25px;
		box-sizing: border-box;
	}
	.food_item {
		// width: calc((100% - 25px) / 2);
		height:186px;
		margin-bottom: 25px;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-size: 15px;
		font-weight: bold;
	}
	.food_image {
		height: 100px;
		width: 100px;
	}
	.food_sum {
		font-size: 12px;
		color: #979797;
		margin: 4px 0 8px 0;
		font-weight: 400;
	}
	.food_price {
		margin-bottom: 8px;
	}
	.more_btn {
		width: 100%;
		padding: 20px 0;
		text-align: center;
	}
	.nva_btn {
		margin-bottom: 20px;
		background: #000000;
		color: #ffffff;
		font-size: 14px;
		font-weight: bold;
	}
	.example-body {
		padding: 0;
		display: block;
	}
	
	.goods-carts {
		display: flex;
		flex-direction: column;
		position: fixed;
		left: 0;
		right: 0;
		/* #ifdef H5 */
		left: var(--window-left);
		right: var(--window-right);
		/* #endif */
		bottom: 0;
	}
	.pay_wrap {
		width: 100%;
		height: 80px;
		position: fixed;
		bottom: 0;
		background: #ffffff;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 0 20px;
		box-sizing: border-box;
	}
	.pay_btn_wrap {
		display: flex;
		flex-direction: row;
		align-items: center;
	}
</style>
